<template>
    <rx-dialog @handOk="handOk" @cancel="cancel">
        <rx-category-treeeditor
            :cat-key="catKey"
            :edit="false"
            @handSelect="handSelect"
            :async="true"
            :checkToDel="true"
        ></rx-category-treeeditor>
    </rx-dialog>
</template>

<script>
import RxCategoryTreeeditor from '@/components/redxun/rx-category-treeeditor'
import {RxDialog, Util} from "@lowcode/jpaas-common-lib";
export default {
    name: "ChangeCategoryDialog",
    components:{
        RxDialog,
        RxCategoryTreeeditor
    },
    props: {
        layerid: {
            type: String,
            default: ""
        },
        destroy: {
            type: Function
        },
        catKey: {
            type: String,
            default: "FORM"
        },
    },
    data() {
        return {
            categoryId:""
        }
    },
    methods:{
        i18n(name, text, key) {
            return this.$ti18(name, text, "changeCategory", key);
        },
        handSelect(curRow){
            this.categoryId = curRow.treeId;
            if(this.categoryId == "0"){
                this.$message.warning(this.i18n("notTopCategory","不能选择顶部分类！"));
            }
        },
        handOk(vm) {
            if(!this.categoryId){
                this.$message.warning(this.i18n("notSelect","未选择分类！"));
                vm.loading = false;
                return;
            }
            if(this.categoryId == "0"){
                this.$message.warning(this.i18n("notTopCategory","不能选择顶部分类！"));
                vm.loading = false;
                return;
            }
            Util.closeWindow(this, "ok",this.categoryId);
        },
        cancel() {
            Util.closeWindow(this, "cancel");
        }
    }
}
</script>

<style scoped>

</style>